package cn.fivestars.springcloud.order.controller;

import cn.fivestars.springcloud.commons.entities.CommonResult;
import cn.fivestars.springcloud.commons.entities.Payment;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * OrderController
 *
 * @author liangchenzhou1024@163.com
 * @date 2021/2/1
 */
@RestController
@RequestMapping("/order")
public class OrderZkController {

    public static final String PAYMENT_URL = "http://cloud-payment-zk-service";

    @Resource
    private RestTemplate restTemplate;

    @PostMapping("/payment/")
    public CommonResult<Payment> save(@RequestBody Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL + "/payment/", payment, CommonResult.class);
    }


    @GetMapping("/payment/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") Long id) {
        return restTemplate.getForObject(PAYMENT_URL + "/payment/" + id, CommonResult.class);
    }


}
